package cn.fz.controller;

import cn.fz.entity.User;
import cn.fz.event.publish.LoginApplicationEvent;
import cn.fz.event.publish.MyApplicationEventPublisherAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * https://blog.csdn.net/yprufeng/article/details/131926977
 * ④创建一个控制器LoginController，用于登录业务处理，并发布登录事件
 */
@RestController
@RequestMapping("/index")
public class LoginController {
    @Autowired
    private MyApplicationEventPublisherAware myApplicationEventPublisherAware;

    @GetMapping("login")
    public String login() {
        //发布登录事件
        myApplicationEventPublisherAware.publishEvent(new LoginApplicationEvent(new User()
                .setUsername("xiaoming").setPassword("123456")));
        //todo 主流程业务处理

        return "ok";
    }
}
